<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of StatementAbuse
 *
 * @author tuancasi
 */
class StatementAbuse extends CActiveRecord {

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return User the static model class
     */
    public static function model($className = __CLASS__) {
	return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
	return '{{statement_abuses}}';
    }

    public function rules() {
	return array(
	    array('statement_abuse_id, text, time_created', 'safe')
	);
    }

    public function afterSave() {
	parent::afterSave();
	$aStateMentAbuse = Yii::app()->cache->get('aStatementAbuse');
	if ($aStateMentAbuse) {
	    Yii::app()->cache->delete(aStatementAbuse);
	}
	_clearCache('aStatementAbuse');
    }

    public function afterDelete() {
	parent::afterDelete();
	$aStateMentAbuse = Yii::app()->cache->get('aStatementAbuse');
	if ($aStateMentAbuse) {
	    Yii::app()->cache->delete(aStatementAbuse);
	}
	_clearCache('aStatementAbuse');
    }

    public static function getStatement() {
	$aStateMentAbuse = Yii::app()->cache->get('aStatementAbuse');
	if ($aStateMentAbuse === false) {
	    $aStateMentAbuse = Yii::app()->db->createCommand("SELECT * FROM {{statement_abuses}}")->queryAll();
	    if ($aStateMentAbuse) {
		Yii::app()->cache->set('aStatementAbuse', $aStateMentAbuse);
	    } else {
		$aStateMentAbuse = array();
	    }
	}
	return $aStateMentAbuse;
    }

    public function search() {
	// Warning: Please modify the following code to remove attributes that
	// should not be searched.

	$criteria = new CDbCriteria;
	$criteria->compare('statement_abuse_id', $this->statement_abuse_id, true);
	$criteria->compare('text', $this->text, true);
	//order
	$criteria->order = 't.time_created DESC';

	return new CActiveDataProvider($this, array(
	    'criteria' => $criteria,
	    'pagination' => array(
		'pageSize' => param('pageSize')
	    )
	));
    }

}

